<?php

function rshl_get_raw_name ($name)
{
	$name = strtolower(str_replace(' ', '_', trim($name, "\r\n\t _")));

	if (!preg_match('/^[a-z0-9]([a-z0-9_]*[a-z0-9])?$/', $name))
	{
		throw new InvalidNameException("'$name' is not a valid character name");
	}

	return $name;
}

function rshl_get_formatted_name ($name)
{
	$name = rshl_get_raw_name($name);
	$name = str_replace('_', ' ', $name);
	$name = ucwords($name);

	return $name;
}

function rshl_get_html_name ($name)
{
	$name = rshl_get_formatted_name($name);
	$name = str_replace(' ', '&nbsp;', $name);

	return $name;
}

